#!/bin/bash
#==============================================================#
# File      :   switch
# Desc      :   render Vagrant file according to spec & template
# Ctime     :   2022-10-16
# Mtime     :   2022-10-17
# Path      :   vagrant/switch
# Usage     :   vagrant/switch [spec=default]
#                              (build|full|el7|el8|el9|...)
# Author    :   Ruohang Feng (rh@vonng.com)
# License   :   AGPLv3
#==============================================================#
SCRIPT_NAME="$(basename $0)"
SCRIPT_DIR="$(cd $(dirname $0) && pwd)"

SPEC=${1-'default'}
SPEC_DIR="${SCRIPT_DIR}/spec"
SPEC_FILENAME="${SPEC}.rb"
SPEC_FILEPATH="${SPEC_DIR}/${SPEC_FILENAME}"
TEMPLATE_PATH="${SPEC_DIR}/Vagrantfile"
VAGRANTFILE_PATH="${SCRIPT_DIR}/Vagrantfile"

printf "\033[0;32m[INFO] switch to ${SPEC} => ${SPEC_FILEPATH} \033[0m\n" >&2
cat ${SPEC_FILEPATH} > ${VAGRANTFILE_PATH};
cat ${TEMPLATE_PATH} >> ${VAGRANTFILE_PATH}
cat ${SPEC_FILEPATH}
